package ru.efimmatytsin.tweeterella.converters;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import ru.efimmatytsin.tweeterella.entities.Tweet;
import ru.efimmatytsin.tweeterella.viewmodels.TweetViewModel;

/**
 * Created by Efim Matytsin on 28.02.15.
 */
@Component
public class TweetViewModelConverter implements Converter<Tweet,TweetViewModel> {

    @Override
    public TweetViewModel convert(Tweet tweet) {
        TweetViewModel tweetViewModel = new TweetViewModel();
        tweetViewModel.setCreated(tweet.getCreated());
        tweetViewModel.setFromUserId(tweet.getFromUser().getId().toString());
        tweetViewModel.setId(tweet.getId().toString());
        tweetViewModel.setText(tweet.getText());
        if(tweet.getReplyFrom()!=null){
            tweetViewModel.setReplyFrom(this.convert(tweet.getReplyFrom()));
        }
        return tweetViewModel;
    }
}
